package github.pop.ares.network;

import github.pop.ares.Utils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;

import java.nio.charset.StandardCharsets;

public class Networking {

    public static SimpleChannel INSTANCE;
    public static final String VERSION = "1.0";
    private static int ID = 0;

    public static int nextID(){
        return ID++;
    }

    public static void registerMessage(){
        // open new channel
        INSTANCE  = NetworkRegistry.newSimpleChannel(
                new ResourceLocation(Utils.MOD_ID,
                        "first_networking"),
                ()->VERSION,
                (version)->version.equals(VERSION),
                (version)->version.equals(VERSION)
        );
        INSTANCE.messageBuilder(
                SendPack.class,nextID())//nextID will create a not non-repeat serializeId
                .encoder(SendPack::toBytes)
                .decoder(SendPack::new)
                .consumer(SendPack::handler)
                .add();// append custom package protocol
    }

}
